package com.sugon.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.ToolsTypeDao;
import com.sugon.entity.ToolsTypeEntity;
import com.sugon.service.ToolsTypeService;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 工装类别Service实现类
 *
 * @author sugon
 * @date 2019-08-01 09:04:32
 */
@Service("toolsTypeService")
public class ToolsTypeServiceImpl implements ToolsTypeService {
    @Autowired
    private ToolsTypeDao toolsTypeDao;

    @Override
    public ToolsTypeEntity queryObjectByTypeCode(String typeCode) {
        Map<String, Object> param = new HashMap<>(1);
        param.put("typeCode",typeCode);
        List<ToolsTypeEntity> toolsTypeList = queryList(param);
        return CollectionUtil.isNotEmpty(toolsTypeList) ? toolsTypeList.get(0) : null;
    }

    @Override
    public ToolsTypeEntity queryObject(String id) {
        return toolsTypeDao.queryObject(id);
    }

    @Override
    public List<ToolsTypeEntity> queryList(Map<String, Object> map) {
        return toolsTypeDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return toolsTypeDao.queryTotal(map);
    }

    @Override
    public int save(ToolsTypeEntity toolsType) {
        toolsType.setId(RandomUtil.randomString(32));
        toolsType.setCreateUser(ShiroUtils.getUserId());
        toolsType.setCreateTime(new Date());
        return toolsTypeDao.save(toolsType);
    }

    @Override
    public int update(ToolsTypeEntity toolsType) {
        toolsType.setUpdateUser(ShiroUtils.getUserId());
        toolsType.setUpdateTime(new Date());
        return toolsTypeDao.update(toolsType);
    }

    @Override
    public int delete(String id) {
        return toolsTypeDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return toolsTypeDao.deleteBatch(ids);
    }
}
